//
//  ViewController.m
//  Gunz
//
//  Created by Joggy on 15/12/11.
//  Copyright © 2015年 NUPT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self prepareForLayout];
//    [self locate];
    
//    NSArray *loc = [NSLocale preferredLanguages];
//    NSLog(@"%@", [loc objectAtIndex:0]);
    
}

-(void)prepareForLayout {
    _main = [[MainViewController alloc]init];
    UINavigationController *mainNav = [[UINavigationController alloc]initWithRootViewController:_main];
    UITabBarItem *mainItem = [[UITabBarItem alloc] init];
    mainItem.image = [UIImage imageNamed:@"tabbar_0_sut"];
    mainItem.title = @"首页";
    mainNav.tabBarItem = mainItem;
    _text = [[TextViewController alloc]init];
    UINavigationController *textNav = [[UINavigationController alloc]initWithRootViewController:_text];
    UITabBarItem *textItem = [[UITabBarItem alloc] init];
    textItem.image = [UIImage imageNamed:@"tabbar_1_sut"];
    textItem.title = @"任务";
    textNav.tabBarItem = textItem;
    _mine = [[MineViewController alloc]init];
    UINavigationController *mineNav = [[UINavigationController alloc]initWithRootViewController:_mine];
    UITabBarItem *mineItem = [[UITabBarItem alloc] init];
    mineItem.image = [UIImage imageNamed:@"tabbar_2_sut"];
    mineItem.title = @"我的";
    mineNav.tabBarItem = mineItem;
    _setting = [[SettingViewController alloc]init];
    UINavigationController *settingNav = [[UINavigationController alloc]initWithRootViewController:_setting];
    UITabBarItem *settingItem = [[UITabBarItem alloc] init];
    settingItem.image = [UIImage imageNamed:@"tabbar_3_sut"];
    settingItem.title = @"设置";
    settingNav.tabBarItem = settingItem;
    self.viewControllers = @[mainNav, textNav, mineNav, settingNav];
    //
    self.tabBar.tintColor = BGGREEN;
    self.tabBar.alpha = 0.9;
}

-(void)prepareForNav {
    
}

-(void)locate {
    if([CLLocationManager locationServicesEnabled]) {
        NSLog(@"true");
        locationManager = [[CLLocationManager alloc] init];
        locationManager.delegate = self;
    }
    else {
        NSLog(@"false");
    }
    [locationManager startUpdatingLocation];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma 代理方法

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations {
    CLLocation *curLocation = [locations lastObject];
    NSLog(@"%@", curLocation);
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    [geocoder reverseGeocodeLocation:curLocation completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {
        if (placemarks.count>0) {
            CLPlacemark *placemark = placemarks.lastObject;
            NSLog(@"%@", placemark.name);
            NSLog(@"%@", placemark.locality);
        }
    }];
    [locationManager stopUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    if (error) {
        NSLog(@"%ld", (long)error.code);
    }
}

@end







